<template>
  <el-menu
    active-text-color="#ffd04b"
    background-color="#545c64"
    class="el-menu-vertical-demo"
    :default-active="activeIndex"
    text-color="#fff"
    @open="handleOpen"
    @close="handleClose"
    :collapse="store.state.menu.isCollapse"
    :collapse-transition="true"
    :style="{ width: store.state.menu.isCollapse ? '64px' : '160px' }"
    router
  >
    <p class="biaoti" :class="{ 'collapse-title': store.state.menu.isCollapse }">
      {{ store.state.menu.isCollapse ? '王平科' : '王平科陪诊' }}
    </p>
    <tree-menu @open="handleOpen" @close="handleClose"/>
  </el-menu>
</template>

<script lang="ts" setup>
import TreeMenu from './treeMenu.vue'
import { useRouter } from 'vue-router'
import { useStore } from 'vuex'
import { ref } from 'vue'

const router = useRouter()
const store = useStore()

const handleOpen = (key: string, keyPath: string[]) => {
  console.log(key, keyPath)
}
const handleClose = (key: string, keyPath: string[]) => {
  console.log(key, keyPath)
}

const activeIndex = ref(router.currentRoute.value.path)
</script>

<style lang="less" scoped>
.el-menu-vertical-demo {
  height: 100vh;
  border-right: none;
  transition: width 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}

.biaoti {
  margin: 0;
  padding: 0 10px;
  height: 50px;
  line-height: 50px;
  font-size: 16px;
  text-align: center;
  color: var(--el-menu-text-color);
  background-color: var(--el-menu-bg-color);
  font-family: var(--el-font-family);
  font-weight: var(--el-font-weight-primary);
  transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  width: 100%;
}

.collapse-title {
  padding: 0;
  text-align: center;
}

:deep(.el-menu) {
  border-right: none;
  
  .el-sub-menu__title,
  .el-menu-item {
    transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
  }
}

:deep(.el-menu--collapse) {
  width: 64px !important;
  
  .el-sub-menu__title span,
  .el-menu-item span {
    display: none;
    transition: opacity 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    opacity: 0;
  }
}

:deep(.el-sub-menu__icon-arrow) {
  transition: transform 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}
</style>